package com.dkakunsi.monev.entity;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="INDIKATOR")
public class Indikator implements MonevNameableEntity {
	private int id;
	private Kegiatan kegiatan;
	private String nama;
	private String satuan;
	private double target;
	private double progres;
	private List<RealisasiIndikator> listRealisasiIndikator;
	
	public Indikator() { }

	public Indikator(Kegiatan kegiatan, String nama, String satuan, double target) {
		setKegiatan(kegiatan);
		setNama(nama);
		setSatuan(satuan);
		setTarget(target);
	}

	@Id @GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="id", length=11, nullable=false)
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@ManyToOne(fetch=FetchType.EAGER)
	@JoinColumn(name="kegiatan", nullable=false)
	public Kegiatan getKegiatan() {
		return kegiatan;
	}

	public void setKegiatan(Kegiatan kegiatan) {
		this.kegiatan = kegiatan;
	}

	@Column(name="nama", length=100, nullable=false)
	public String getNama() {
		return nama;
	}

	public void setNama(String nama) {
		this.nama = nama;
	}

	@Column(name="satuan", length=100, nullable=false)
	public String getSatuan() {
		return satuan;
	}

	public void setSatuan(String satuan) {
		this.satuan = satuan;
	}

	@Column(name="target", nullable=true)
	public double getTarget() {
		return target;
	}

	public void setTarget(double target) {
		this.target = target;
	}

	@Column(name="progres", nullable=true)
	public double getProgres() {
		return progres;
	}

	public void setProgres(double realisasi) {
		this.progres = realisasi;
	}

	@OneToMany(mappedBy="indikator", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
	public List<RealisasiIndikator> getListRealisasiIndikator() {
		return listRealisasiIndikator;
	}

	public void setListRealisasiIndikator(List<RealisasiIndikator> listRealisasiIndikator) {
		this.listRealisasiIndikator = listRealisasiIndikator;
	}

	public double presentaseProgres() {
		return (progres / target) * 100;
	}
}
